<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>

<body>
    <div id="app">
        <!-- 使用子组件 -->
        <part @myevent="getvalueFn"></part>
    </div>
</body>

</html>
<script>
    // 父传子: 方式3;
    // 在子组件中通过$emit 方法将子组件中的函数传递给父组件,然后在父组件拿到函数,并且调用函数,
    // 该函数的返回值就是子组件中的数据

    const { createApp } = Vue;
    const vm = createApp({
        data() {
            return {
                count: 0
            }
        },
        methods: {
            getvalueFn(fn) {
                // console.log(fn);
                console.log('fn', fn());
            }

        },
        components: {
            part: {
                template: `<div>
                              <p @click='tofatherFn'>子组件</p>
                          </div>`,
                data() {
                    return {
                        count1: 100
                    }
                },
                methods: {
                    getdatafromfather() {
                        // console.log('data', data);
                        return this.count1
                    },
                    tofatherFn() {
                        // 子传父
                        this.$emit('myevent', this.getdatafromfather)
                    }
                }
            }
        }


    });

    //挂载根实例到根节点
    vm.mount('#app')

</script>